
package gui;

import business.Pessoa;
import java.util.Locale;
import java.util.ResourceBundle;
import gui.Principal;

public class Login extends javax.swing.JFrame {

    public Login() {
        initComponents();
       // jPasswordFieldLoginSenha.setEnabled(false);
        setLocationRelativeTo(null);
    }

     private ResourceBundle bundle;
    
     public void atualizabarra() {
        
        bundle = ResourceBundle.getBundle("gui/Bundle");
        
        //jRadioButton1.setText(bundle.getString("Login.jRadioButton1.text"));
        //jRadioButton2.setText(bundle.getString("Login.jRadioButton2.text"));
        jLabelLoginUsuario.setText(bundle.getString("Login.jLabelLoginUsuario.text"));
        jLabelLoginSenha.setText(bundle.getString("Login.jLabelLoginSenha.text"));
        
   
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jTextFieldLoginUsuario = new javax.swing.JTextField();
        jLabelLoginUsuario = new javax.swing.JLabel();
        jLabelLoginSenha = new javax.swing.JLabel();
        jButtonLoginLogin = new javax.swing.JButton();
        jPasswordFieldLoginSenha = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("gui/Bundle"); // NOI18N
        jLabel1.setText(bundle.getString("Login.jLabel1.text")); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle(bundle.getString("Login.title")); // NOI18N
        setResizable(false);

        jTextFieldLoginUsuario.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        jLabelLoginUsuario.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelLoginUsuario.setText(bundle.getString("Login.jLabelLoginUsuario.text")); // NOI18N

        jLabelLoginSenha.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelLoginSenha.setText(bundle.getString("Login.jLabelLoginSenha.text")); // NOI18N

        jButtonLoginLogin.setFont(new java.awt.Font("Tahoma", 0, 18));
        jButtonLoginLogin.setText(bundle.getString("Login.jButtonLoginLogin.text")); // NOI18N
        jButtonLoginLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLoginLoginActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel2.setText(bundle.getString("Login.jLabel2.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelLoginUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelLoginSenha))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldLoginUsuario)
                    .addComponent(jPasswordFieldLoginSenha)
                    .addComponent(jButtonLoginLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(116, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(208, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(196, 196, 196))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 84, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldLoginUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelLoginUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jPasswordFieldLoginSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelLoginSenha))
                .addGap(18, 18, 18)
                .addComponent(jButtonLoginLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonLoginLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLoginLoginActionPerformed
   //   String senha = PessoaDAO.getPEssoaSenhaPorUsuario(jTextFieldLoginUsuario.getText());
      //  if (jPasswordFieldLoginSenha.getPassword().equals(senha.toCharArray())){
///            dispose();
///            Principal.getInstance().setVisible(true);
///            FuncionarioVO funcionario = new FuncionarioVO();
///            Principal.getInstance().setFuncionarioLogado(funcionario);
///            Principal.getInstance().getFuncionarioLogado().setCpf("35279580880");
      //  }TOUDO QUE ESTA C 3 / estava ativo
      //  else
           //JOptionPane.showMessageDialog(this,"Senha ou usuário incorretos.");
     if(!Pessoa.EhFuncionario(jTextFieldLoginUsuario.getText()))  
     {
            jPasswordFieldLoginSenha.setText("");
            jTextFieldLoginUsuario.setText("");       
     }
     else
     {
        
      String Senha=Pessoa.getPessoaSenhaPorUsuario(jTextFieldLoginUsuario.getText());
        // System.out.println(Senha);
       // System.out.println(jPasswordFieldLoginSenha.getPassword().toString());
        if(!Senha.equals(jPasswordFieldLoginSenha.getText()))
        {
            jPasswordFieldLoginSenha.setText("");
            jTextFieldLoginUsuario.setText("");
   
        }
        else
        {
             Principal.getInstance().setVisible(true);
             String Logado=Pessoa.getPessoaCPFPorUsuario(jTextFieldLoginUsuario.getText());
             Principal.getInstance().setFuncionarioLogado(jTextFieldLoginUsuario.getText());
             dispose();
        }

     }   
    }//GEN-LAST:event_jButtonLoginLoginActionPerformed

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonLoginLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelLoginSenha;
    private javax.swing.JLabel jLabelLoginUsuario;
    private javax.swing.JPasswordField jPasswordFieldLoginSenha;
    private javax.swing.JTextField jTextFieldLoginUsuario;
    // End of variables declaration//GEN-END:variables
}
